import java.util.*;
import java.util.stream.Stream;

public class Test2 {
    public static void main(String[] args) {
        // 如何获取List集合的Stream流？
        List<String> list = new ArrayList<>();
        Collections.addAll(list, "张三", "李四", "王五");
        Stream<String> stream = list.stream();
        stream.filter(s -> s.contains("五")).forEach(s -> System.out.println(s));

        //如何获取Set集合的Stream流？
        Set<String> set = new HashSet<>();
        Collections.addAll(set, "张三", "李四", "王五");
        Stream<String> stream1 = set.stream();
        stream1.filter(s -> s.contains("五")).forEach(System.out::println);

        // 如何获取Map集合的Stream流？
        Map<String, Integer> map = new HashMap<>();
        map.put("张三", 23);
        map.put("张无忌", 25);
        map.put("刘三", 23);
        map.put("马二", 23);
        map.put("张X", 23);
//        map.keySet().stream().filter(s -> s.contains("张")).forEach(System.out::println);
//        map.values().stream().filter(i -> i > 23).forEach(System.out::println);

        Set<Map.Entry<String, Integer>> entries = map.entrySet();
        entries.stream().filter(e -> e.getKey().contains("张")).forEach(e -> System.out.println(e.getKey()+"->"+e.getValue()));

        // 如何获取数组的Stream流？
        String[] names = {"张哈哈", "马自大", "张牛", "刘xx"};
        Stream<String> stream2 = Arrays.stream(names);
        stream2.filter(s -> s.contains("张")).forEach(System.out::println);
    }
}
